package com.flyox.game.militarychess.bean;

import java.io.Serializable;
import java.security.KeyPair;
import java.security.PublicKey;
import java.util.Date;

import javax.crypto.SecretKey;

import org.apache.mina.common.IoSession;

import com.flyox.game.militarychess.CONSTS;
import com.flyox.game.militarychess.bean.ChessSeat.SEAT_NAME;
import com.flyox.game.militarychess.util.Secret;
import com.flyox.game.militarychess.util.SysUtil;


public class Player implements Serializable{

	private static final long serialVersionUID = 5118503005991671469L;
	private String id;//唯一键
	private String name="";//single
	private String pass="";//after md5
	private int states=CONSTS.PLAYER_STATS_NOLOGIN;//0:未登录   1：hello，2：CMD_HAND_1, 3：CMD_HAND_2    2 登录，3 空闲，4坐下，5开始，6失败，7胜利。
	private int score=0;//得分
	private KeyPair keyPair;//本地对应密钥对
	private SecretKey desKey;//本地密钥
	private PublicKey otherSidePubKey;
	private Date loginTime;//最后一次联系时间
	private int overtimeTimes=0;//超时次数
	
	private int deskNum;//桌号
	private SEAT_NAME seatName;//座位号
	
	private IoSession session;//链接状态
	
	public IoSession getSession() {
		return session;
	}

	public void setSession(IoSession session) {
		this.session = session;
	}

	public SEAT_NAME getSeatName() {
		return seatName;
	}

	public void setSeatName(SEAT_NAME seatName) {
		this.seatName = seatName;
	}

	public static String genPlayerID() {
		return Secret.genDigest(String.valueOf(SysUtil.genID()));
	}
	
	public Player(String id){
		this.id=id;
	}
	
	public Date getLoginTime() {
		return loginTime;
	}
	public void setLoginTime(Date loginTime) {
		this.loginTime = loginTime;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public int getStates() {
		return states;
	}
	public void setStates(int states) {
		this.states = states;
		loginTime=new Date();
	}
	public int getScore() {
		return score;
	}
	public void setScore(int score) {
		this.score = score;
	}
	public String getPass() {
		return pass;
	}
	public void setPass(String pass) {
		this.pass = pass;
	}

	public SecretKey getDesKey() {
		return desKey;
	}

	public void setDesKey(SecretKey desKey) {
		this.desKey = desKey;
	}

	public KeyPair getKeyPair() {
		return keyPair;
	}

	public void setKeyPair(KeyPair keyPair) {
		this.keyPair = keyPair;
	}

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public int getDeskNum() {
		return deskNum;
	}

	public void setDeskNum(int deskNum) {
		this.deskNum = deskNum;
	}

	public PublicKey getOtherSidePubKey() {
		return otherSidePubKey;
	}

	public void setOtherSidePubKey(PublicKey otherSidePubKey) {
		this.otherSidePubKey = otherSidePubKey;
	}

	public int getOvertimeTimes() {
		return overtimeTimes;
	}

	public void setOvertimeTimes(int overtimeTimes) {
		this.overtimeTimes = overtimeTimes;
	}

	
}
